import { ipcRenderer, contextBridge } from "electron";

// --------- Expose some API to the Renderer process ---------
contextBridge.exposeInMainWorld("ipcRenderer", {
  on(...args: Parameters<typeof ipcRenderer.on>) {
    const [channel, listener] = args;
    return ipcRenderer.on(channel, (event, ...args) => listener(event, ...args));
  },
  off(...args: Parameters<typeof ipcRenderer.off>) {
    const [channel, ...omit] = args;
    return ipcRenderer.off(channel, ...omit);
  },
  send(...args: Parameters<typeof ipcRenderer.send>) {
    const [channel, ...omit] = args;
    return ipcRenderer.send(channel, ...omit);
  },
  invoke(...args: Parameters<typeof ipcRenderer.invoke>) {
    const [channel, ...omit] = args;
    return ipcRenderer.invoke(channel, ...omit);
  },

  // You can expose other APTs you need here.
  // ...
});

// preload.js
document.addEventListener("DOMContentLoaded", function () {
  // 禁用表单元素的自动填充
  document.querySelectorAll("input, textarea").forEach(function (element) {
    element.setAttribute("autocomplete", "off");
  });

  // 如果你想进一步阻止某些特定元素的自动填充
  // 你可以根据需要选择这些元素
  // 例如：
  // document.getElementById('myInput').setAttribute('autocomplete', 'off');
});
